package servlet;

import dao.UserDao;
import bean.Result;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RemoveUserServlet", value = "/RemoveUserServlet.s")
public class RemoveUserServlet extends HttpServlet {
    private UserDao dao =new UserDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String uid = request.getParameter("uid");
        final String flag = request.getParameter("flag");
        //逻辑删除则需要修改status
        final String status = request.getParameter("status");
        Result result =null;

        if ("物理删除".equals(flag)){
            dao.removeUser(uid);
        }else if("逻辑删除".equals(flag)){
            dao.modifyStatus(uid,status);
            if ("1".equals(status)){
                result = new Result(1,"用户账号恢复使用",null);
            }else if ("0".equals(status)){
                result = new Result(0,"用户账号被禁用",null);
            }
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
